package cn.edu.jxau.core.Filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;

/**
 * 用户登录状态过滤器
 * @author Aaron
 *
 */
public class UserFilter implements Filter {

	@Override
	public void destroy() {
		

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
			throws IOException, ServletException {
		HttpServletRequest hreq = (HttpServletRequest) request;  
		HttpSession session = hreq.getSession();
		HashMap<String, Object> user_session = (HashMap<String, Object>) session.getAttribute("session_user");
		if (null == user_session) { 
			HttpServletResponse hresp = (HttpServletResponse) response;
			hresp.sendRedirect("/spectrum3/login.jsp");
		}
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		

	}

}
